import { defineStore } from 'pinia';
import { useMenuApi } from '../api/menu';
/**
 * 用户信息
 * @methods setUserInfos 设置用户信息
 * @methods  setPermission 设置用户按钮信息
 */
export const useUserInfo = defineStore('userInfo', {
	state: (): UserInfosState => ({
		permission: {
			authBtnList: [],
		},
		userInfos: {
			account: "",
			department: 0,
			description: "",
			email: "",
			englishname: "",
			fid: 0,
			gender: 1,
			id: 0,
			phone: "",
			roles: [],
			username: ""
		}
	}),
	actions: {
		async setUserInfos(userInfo: UserInfos) {
			this.userInfos = userInfo;
		},
		async setPermission() {
			await useMenuApi().getBtn().then(res => {
				this.permission.authBtnList = res.result.map((v: any) => v.permission);
			})
		},
	},
});
